﻿using System;
using System.Linq;
using Devbridge.IPolice.DataContracts;
using Devbridge.IPolice.DomainModel;
using Devbridge.IPolice.Repositories.DataContext;
using NHibernate;
using NHibernate.Linq;

namespace Devbridge.IPolice.Repositories
{
    public class OffenderRepository : IOffenderRepository
    {
        private readonly ISession session;

        public OffenderRepository()
        {
            session = SessionFactoryProvider.OpenSession();
        }

        /// <summary>
        /// Gets the by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>Entity by id.</returns>
        public Offender GetById(int id)
        {
            return session.Get<Offender>(id);            
        }

        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        public void Save(Offender entity)
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// Removes the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        public void Remove(Offender entity)
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// Alls the query.
        /// </summary>
        /// <returns>Query to get all entities</returns>
        public IQueryable<Offender> AllQuery()
        {
            return session.Query<Offender>();
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            session.Close();
            session.Dispose();
        }
    }
}
